package heman.server.controllers;

import heman.server.entities.PlayerManager;




import ks.framework.common.Message;
import ks.framework.communicator.Communicator;
import ks.server.interfaces.IProcessServerMessage;

import org.w3c.dom.Document;


/**
 * Table controller handles the request of "players".
 * 
 * 
 * 
 * <response version="1.0" id="589a39591271844e3fbe32bbb9281ad9" success="true">
- <playerResponse>
- <player player="1213" realName="George Heineman">
  <rating category="solitaire" value="229" /> 
  <rating category="wordsteal" value="1234" /> 
  </player>
- <player player="1217">
  <rating category="solitaire" value="2983" /> 
  </player>
  </playerResponse>
  </response>

 * 
 * @author Wenlong Liu
 *
 */
public class PlayersController implements IProcessServerMessage {

	public boolean process(Communicator com, Message m) {
		String originator = m.getOriginator();
        
        // produce successful request. note that client is responsible 
        // now for tagging from.
        StringBuilder sb = new StringBuilder(Message.responseHeader(true,m.id));
        //sb.append("")
        sb.append("<playerResponse>");
        
        sb.append(PlayerManager.getInstance().getAllPlayersXML());
        sb.append("</playerResponse></response>");
        
        Document d = Message.construct(sb.toString());
        
        Message r = new Message (d);
        r.setOriginator(originator);
        r.setRecipient(originator);
        return com.distribute(r);
       
	}

}
